package com.zhaoyu.article.controller;

import com.zhaoyu.apis.article.ApArticleControllerApi;
import com.zhaoyu.article.service.ApArticleService;
import com.zhaoyu.common.constants.ArticleConstants;
import com.zhaoyu.model.article.dto.ArticleHomeDto;
import com.zhaoyu.model.article.dto.ArticleInfoDto;
import com.zhaoyu.model.article.pojos.ApArticle;
import com.zhaoyu.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController implements ApArticleControllerApi {

    @Autowired
    private ApArticleService apArticleService;

    @Override
    @PostMapping("/save") // json格式的数据
    public ApArticle saveApArticle(@RequestBody ApArticle apArticle) {
        apArticleService.save(apArticle);
        return apArticle;
    }

    /**
     * 1为加载更多
     * 2为加载最新
     */
    @Override
    @PostMapping("/load") // json格式的数据
    public ResponseResult loadApArticle(@RequestBody ArticleHomeDto articleHomeDto) {
        return apArticleService.load(ArticleConstants.LOADMORE,articleHomeDto);
    }

    @Override
    @PostMapping("/loadMore") // json格式的数据
    public ResponseResult loadMoreApArticle(@RequestBody ArticleHomeDto articleHomeDto) {
        return apArticleService.load(ArticleConstants.LOADMORE,articleHomeDto);
    }

    @Override
    @PostMapping("/loadNew") // json格式的数据
    public ResponseResult loadNewApArticle(@RequestBody ArticleHomeDto articleHomeDto) {
        return apArticleService.load(ArticleConstants.LOADNEW,articleHomeDto);
    }

    @Override
    @PostMapping("/loadInfo") // json格式的数据
    public ResponseResult loadApArticleInfo(ArticleInfoDto articleInfoDto) {
        return apArticleService.loadApArticleInfo(articleInfoDto);
    }

}